package com;

import com.alibaba.druid.pool.DruidDataSource;
import com.alibaba.druid.pool.DruidPooledConnection;

import java.sql.SQLException;

public class Demo03Druid {
    public static void main(String[] args) {
        DruidDataSource dataSource = new DruidDataSource();
        dataSource.setDriverClassName("com.mysql.jdbc.Driver");
        dataSource.setUrl("jdbc:mysql://125.74.233.192:3306/fruitdb?" +
                "characterEncoding=utf-8&rewriteBatchedStatements=true");
        dataSource.setUsername("root");
        dataSource.setPassword("123456123");
        //1、设置数据源的初始大小2
        dataSource.setInitialSize(2);
        //2、设置数据源的最大活动连接数为5
        dataSource.setMaxActive(5);
        //3、设置数据源的最大等待时间5000毫秒
        dataSource.setMaxWait(5000);
        //4、循环创建10个连接
        for (int i = 0; i < 10; i++) {
            try {
                //通过连接池创建连接
                DruidPooledConnection connection = dataSource.getConnection();
                System.out.println("connection = "+i+"====="+connection);
            } catch (SQLException e) {
                throw new RuntimeException(e);
            }


        }
    }

}
